#include <bits/stdc++.h>
using namespace std;
const int M=1e6+10;
int t;
int n,m,L,v_limit;
long long v_now;
int d[M],v[M],a[M],p[M];
int s[M][2]={0};
int ans=0;
int temp;
int findcar(int dist)
{
    for(int i=0;i<n;i++){
        if(p[i]>=dist){
            return i;
        }
    }
    return -1;
}
void f()
{
    for(int i=0;i<n;i++){
        s[i][1]=m-1;
        s[i][0]=-1;
    }
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>n>>m>>L>>v_limit;
        f();
        ans=0;
        for(int j=0;j<n;j++){
            cin>>d[j]>>v[j]>>a[j];
        }
        for(int j=0;j<m;j++){
            cin>>p[j];
        }
        for(int j=0;j<n;j++){
            if(a[j]==0){
                int ii=findcar(d[j]);
                if((ii!=-1)&&(v[j]>v_limit)){
                    s[j][0]=ii;
                    ans++;
                    //cout<<j<<endl;
                }
            }else if(a[j]>0){
                int ii=findcar(d[j]);
                for(int k=ii;k<m;k++){
                    v_now=v[j]*v[j]+2*a[j]*(p[k]-d[j]);
                    if(v_now>v_limit*v_limit){
                        ans++;
                        s[j][0]=k;
                        //cout<<j<<endl;
                        break;
                    }
                }
            }else{
                if(v[j]<=v_limit) continue;
                int ii=findcar(d[j]);
                //cout<<ii<<endl;
                for(int k=ii;k<m;k++){
                    v_now=v[j]*v[j]+2*a[j]*(p[k]-d[j]);
                    if(v_now>v_limit*v_limit){
                        ans++;
                        s[j][0]=k;
                        //cout<<v_now<<endl;
                        //cout<<j<<endl;
                        temp=k;
                        break;
                    }
                    if(v_now<=v_limit*v_limit){
                        break;
                    }
                }
                if(s[j][0]!=-1){
                    for(int k=temp+1;k<m;k++){
                        v_now=v[j]*v[j]+2*a[j]*(p[k]-d[j]);
                        if(v_now<=v_limit*v_limit){
                           s[j][1]=k-1;
                           break;
                        }
                    }
                }
            }
        }
        cout<<ans<<" ";
        //for(int j=0;j<n;j++){
        //    cout<<s[j][0]<<" "<<s[j][1]<<endl;
        //}
        int sum=-1;
        for(int j=0;j<n;j++){
            sum=max(sum,s[j][1]-s[j][0]);
        }
        if(ans==0) cout<<m<<endl;
        else cout<<sum-1<<endl;
    }
    return 0;
}
